import { Injectable } from '@angular/core';
import { Observable } from 'rxjs/Observable';
import { Article } from './Article';
import { PageInfo } from './PageInfo';
import { ResponseModel } from './ResponseModel';
import { HttpClient, HttpHeaders } from '@angular/common/http';

const httpOptions = {
  headers: new HttpHeaders({ 'Content-Type': 'application/json', 'X-Requested-With': 'XMLHttpRequest'})
};
@Injectable()
export class HeroService {
  private heroesUrl = '/v1/blog';
  constructor(private http: HttpClient) { }
  getHeroes(pageNo: number): Observable<ResponseModel<PageInfo<Article>>> {
    const url = `${this.heroesUrl}/list?pageNo=${pageNo}`;
    return this.http.get<ResponseModel<PageInfo<Article>>>(url,httpOptions);
  }
  getHero(id: number): Observable<ResponseModel<Article>> {
    const url = `${this.heroesUrl}/get?id=${id}`;
    return this.http.get<ResponseModel<Article>>(url);
  }
  addArticle(article: Article): Observable<number> {
    const url = `${this.heroesUrl}/postArticle`;
    return this.http.post<number>(url, article, httpOptions);
  }

}
